<?php

include_once __DIR__ . '/../vendor/autoload.php';
include_once __DIR__ . '/../db.php';

$type = $_GET['type'];

$nextDraw1 = getNextDraw($type);
$data1 = \Data::where('type', $type)
    ->where('date', '>=', date('Y-m-d', mktime(0, 0, 0, 1, 1, date("Y"))))
    ->where('date', '<', substr($nextDraw1, 0, 10))
    ->orderBy('date', 'asc')
    ->get();
$data1->each(function ($item) {
    $item->date = dateE($item->date);
});

$current1 = $data1->last();

echo json_encode([
    'nextDraw' => $nextDraw1,
    'trending' => $data1,
    'current' => $current1,
]);
